<template>
	<view>
		<view v-if="formDataList.length > 0" class="" v-for="item in formDataList"
			style="background-color: #fff;padding: 20rpx;display: flex;align-items: center;justify-content: space-between;border-radius: 20rpx;margin-bottom: 20rpx;">
			<view class="">
				<view class="" style="font-size: 30rpx;">{{ item.jsonViewData.name }}</view>

				<view class="" style="font-size: 26rpx;margin-top: 20rpx;color: #666;">{{ item.createTime }}</view>
			</view>
			<view v-if="item.dataJson.status==1&&item.signStatus==2" @click="btn(item.signFlowId)"
				style="color:#ff4544 ;display: flex;align-items: center;justify-content: center;">
				电子合同
			</view>
				<view v-if="item.dataJson.status==1&&item.signStatus==0" @click="btn1(item.dataJson.heTong)"
					style="color:#ff4544 ;display: flex;align-items: center;justify-content: center;">
					查看合同
				</view>
			<view class="" v-if="item.dataJson.status == 0">等待签署</view>
			<view class="" v-else style="color:#ff4544 ;display: flex;align-items: center;justify-content: center;"
				@click="addToCart(item)">
				查看
				<uv-icon name="arrow-right" color="#ff4544"></uv-icon>
			</view>
		</view>
		
		<view class="none_list_box" v-if="formDataList.length == 0" style="margin-top: 200rpx"><uv-empty
				mode="data"></uv-empty></view>
	</view>
</template>

<script>
	import {
		getUserSubmitFormDataList,
		searchPlugsDataById,
		getContract
	} from '../../../utils/api.js';
	export default {
		data() {
			return {
				formDataList: []
			};
		},
		onShow() {
			this.getFormDataList();
		},
		methods: {
			getFormDataList() {
				let data = {
					page: 1
				};
				getUserSubmitFormDataList(data).then(res => {
					if (res.code == 200) {
						this.formDataList = res.body.list;
						this.formDataList.forEach((item, index) => {
							item.dataJson = JSON.parse(item.dataJson);
							searchPlugsDataById({
								id: item.dataJson.dataId
							}).then(resss => {
								if (resss.code == 200) {
									this.$set(this.formDataList[index], 'jsonViewData', resss.body
										.jsonViewData);
								}
							});
						});
						console.log(this.formDataList);
					}
				});
			},
			addToCart(item) {
				uni.navigateTo({
					url: `/pages/index/performance/list?info=${encodeURIComponent(JSON.stringify(item))}`
				});
			},
			btn1(arr){
				uni.previewImage({
					urls: arr, //需要预览的图片http链接列表，多张的时候，url直接写在后面就行了
					current:0, // 当前显示图片的http链接，默认是第一个
					success: function(res) {},
					fail: function(res) {},
					complete: function(res) {},
				})
				
			},
			btn(src) {
				let data = {
					signFlowId: src
				}
				getContract(data).then((ress => {
					if (ress.code == 200) {
						let urls = ress.body.data.files[0].downloadUrl
						console.log(urls);
						uni.navigateTo({
							url:`./webView?url=${encodeURIComponent(JSON.stringify(urls))}`
						})
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				}))
			}
		}
	};
</script>

<style lang="scss">
	page {
		background: #f5f5f5;
		padding: 20rpx;
		box-sizing: border-box;
	}

	.list {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #fff;
		padding: 20rpx;
		font-size: 26rpx;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
	}

	.box {
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.title {
			font-size: 28rpx;
			font-weight: 700;
			margin-bottom: 20rpx;
		}
	}

	.butt {
		width: 160rpx;
		height: 60rpx;
		border-radius: 30rpx;
		text-align: center;
		line-height: 60rpx;
		background-color: #ff4544;
		color: #fff;
	}
</style>